package borge.web.teamspirit.client.page.team;

import java.util.ArrayList;
import java.util.List;

import borge.web.teamspirit.client.SessionData;

public class TokenData {

	// different modes we run the application in
	public static final String MAIN_MODE = "Main";
	public static final String TEAM_MODE = "Team";
	public static final String ASSOCIATION_MODE = "Association";
	
	// testing purposes
	public static final String TEST_CREATE = "TestCreate";
	public static final String TEST_PRINT = "TestPrint";
	
	// Panels
	public static final String WELCOME = "Welcome";
	public static final String SHOW = "Show";
	public static final String LIST = "List";
	public static final String SEARCH = "Search";
	public static final String CREATE = "Create";
	public static final String EDIT = "Edit";
	
	// Widget entity type
	public static final String PERSON = "Person";
	public static final String TEAM = "Team";
	public static final String PLAYER = "Player";
	public static final String ASSOCIATION = "Association";
	public static final String LEAGUE = "League";
	public static final String SERIE = "Serie";
	public static final String MATCH = "Match";
	public static final String NEWS = "News";
	public static final String COMMENT = "Comment";
	public static final String EVENT = "Event";
	public static final String FORUM = "Forum";
	public static final String STATISTICS = "Statistics";
	
	
	public static final char TOKENIZER = '/';
	
	
	public static String assembleTeamToken(String aPanel, String aWidget){
		return SessionData.sBaseToken + TOKENIZER + aPanel + TOKENIZER + aWidget;
	}
	
	public static String assembleTeamToken(String aPanel, String aWidget, String... aData){
		String tokens = "";
		for(String s : aData){
			tokens += TOKENIZER + s;
		}
		return assembleTeamToken(aPanel, aWidget) + tokens;
	}
	
	public static String addTokenData(String aToken, String aData){
		return aToken + TOKENIZER + aData;
	}
	
	public static List<String> extractTokens(String aTokens){
		
		List<String> tokens = new ArrayList<String>();
		
		int index = 0, lastIndex = 0;
		
		while((index = aTokens.indexOf(TOKENIZER, index)) != -1){
			
			tokens.add(aTokens.substring(lastIndex, index));
			lastIndex = index + 1;
		}
		
		if(lastIndex < aTokens.length()){
			tokens.add(aTokens.substring(lastIndex, aTokens.length()));
		}
		
		return tokens;
		
	}
	
}
